﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.ComponentModel.DataAnnotations;

namespace MvcHeatloss.Models
{
    [MetadataType(typeof(WindowData))]
    public partial class Window
    {
        public ProjectEntities db = new ProjectEntities();
        
        public Window(double height, double width, string type, int temp)
        {
            WindowArea = CalcHeatoss.CalcArea(height , width);
            WindowType = type;
            WindowUValue = (double)db.UValues.Where(d => d.Description == type).Select(u => u.UValue1).First();
            WindowTemp = temp;
            WindowHeatloss = CalcHeatoss.FabricHeatloss(this.WindowUValue, this.WindowArea, this.WindowTemp);
        }
        public Window(): base()
        {
        }

        public string WindowType { get; set; }
        
        public int WindowTemp { get; set; }
        
        public double WindowUValue { get; set; }

        public double WindowArea { get; set; }

        double windowHeatloss;
        public double WindowHeatloss 
        {
            get
            {
                return windowHeatloss;
            }
            set
            {
                windowHeatloss = CalcHeatoss.FabricHeatloss(this.WindowUValue, this.WindowArea, this.WindowTemp);
            }
        }
    }
    public class WindowData
    {
        [Required(ErrorMessage = "You must enter a total Window Length")]
        [Display(Name = "Window Width")]
        public decimal Width { get; set; }

        [Required(ErrorMessage = "You must enter a Window Height")]
        [Display(Name = "Window Height")]
        public decimal Height { get; set; }

    }
}